<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RGBToHSL</title>
</head>

<body>
    <div>打开浏览器查看结果</div>
    <script>
        const RGBToHSL = (r, g, b) => {
            r /= 255;
            g /= 255;
            b /= 255;

            const l = Math.max(r, g, b);
            const s = l - Math.min(r, g, b);
            const h = s
                ? l === r
                    ? (g - b) / s
                    : l === g
                        ? 2 + (b - r) / s
                        : 4 + (r - g) / s
                : 0;
            return [
                60 * h < 0 ? 60 * h + 360 : 60 * h,
                100 * (s ? (l <= 0.5 ? s / (2 * l - s) : s / (2 - (2 * l - s))) : 0),
                (100 * (2 * l - s)) / 2
            ];
        };
        console.log(RGBToHSL(45, 23, 11)) // [21.17647, 60.71428, 10.98039]
    </script>
</body>

</html>